//
//  UIImage+RoundedCorner.m
//  CJRailTransport
//
//  Created by Hank on 2017/11/21.
//  Copyright © 2017年 amplity. All rights reserved.
//

#import "UIImage+RoundedCorner.h"

@implementation UIImage (RoundedCorner)

- (UIImage*)lc_drawRectWithRoundedCorner:(CGFloat)radius borderWidth:(CGFloat)borderWidth backgroundColor:(UIColor*)backgroundColor borderColor:(UIColor*)borderColor{
    CGSizesizeToFit =CGSizeMake(self.bounds.size.width,self.bounds.size.height);
    CGFloathalfBorderWidth = borderWidth /2.0;
    UIGraphicsBeginImageContextWithOptions(sizeToFit,false, [UIScreenmainScreen].scale);
    CGContextRefcontext =UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, borderWidth);
    CGContextSetStrokeColorWithColor(context, borderColor.CGColor);
    CGContextSetFillColorWithColor(context, backgroundColor.CGColor);
    CGFloatwidth = sizeToFit.width;
    CGFloatheight = sizeToFit.height;
    CGContextMoveToPoint(context, width - halfBorderWidth, radius + halfBorderWidth);//开始坐标右边开始
    CGContextAddArcToPoint(context, width - halfBorderWidth, height - halfBorderWidth, width - radius - halfBorderWidth, height - halfBorderWidth, radius);//右下角角度
    CGContextAddArcToPoint(context, halfBorderWidth, height - halfBorderWidth, halfBorderWidth, height - radius - halfBorderWidth, radius);//左下角角度
    CGContextAddArcToPoint(context, halfBorderWidth, halfBorderWidth, width - halfBorderWidth, halfBorderWidth, radius);//左上角
    CGContextAddArcToPoint(context, width - halfBorderWidth, halfBorderWidth, width - halfBorderWidth, radius + halfBorderWidth, radius);//右上角
    CGContextDrawPath(UIGraphicsGetCurrentContext(),kCGPathFillStroke);
    UIImage*output =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    returnoutput;
}

@end
